﻿@model WarOfDev.EF.Post
@using WarOfDev.Core.Common

@{
    ViewBag.Title = "Details";
}

<h2>Puzzle Details</h2>


    <table>
        <tr>
            <th> @Html.DisplayNameFor(model => model.Title)</th>
            <td>@Html.DisplayFor(model => model.Title)</td>
        </tr>
        <tr>
            <th> @Html.DisplayNameFor(model => model.Content)</th>
            <td>@Html.DisplayFor(model => model.Content)</td>
        </tr>

        <tr>
            <th> @Html.DisplayNameFor(model => model.Tags)</th>
            <td> @Html.DisplayFor(model => model.Tags)</td>
        </tr>

        <tr>
            <th> @Html.DisplayNameFor(model => model.CreatedBy)</th>
            <td> @Model.Developer.NickName</td>
        </tr>

        <tr>
            <th>@Html.DisplayNameFor(model => model.CreatedOn)</th>
            <td>@Model.CreatedOn.Value.ToString("yyyy-MM-dd hh:mm:ss")</td>
        </tr>
    </table>

   

 <h2>Answers</h2>

   

    <table>
        <tbody>
        @foreach (var item in Model.Comments)
        {
            <tr class="title">
                <td>@item.Developer.NickName</td>
                <td>At: @item.CreateOn.Value.ToString("yyyy-MM-dd hh:mm:ss")</td>
                <td>
                    @if (string.IsNullOrEmpty(Model.PickedCommentId)) {
                        <text>PickToBestAnwser:</text>
                        @Html.ActionLink("RewardByMyValueExperience", "PickAnswer" , new { postId = Model.Id, commentId = item.Id, rewardType = (int)EnumPuzzleRewardType.ByExperienceValue });
                        @Html.ActionLink("RewardByDoingWork", "PickAnswer", new { postId = Model.Id, commentId = item.Id, rewardType = (int)EnumPuzzleRewardType.ByWorkForResolover });
                            
                    }
                    else{
                        if(Model.PickedCommentId==item.Id){
                            <text> *** Picked Answer *** </text>
                            if (item.Status == (int)EnumCommentStatus.Rewarding && ViewBag.currentDeveloperId==item.CreateBy) { 
                                @Html.ActionLink("Close", "ReceiveReward", new {commentId=item.Id });
                            }
                        }
                    }

                </td>
            </tr>
            <tr>
                <td colspan="3" class="content">
                    @item.Commend
                </td>
            </tr>
        }
        </tbody>
    </table>

    @if (ViewBag.currentDeveloperId != Model.CreatedBy)
    {
        <legend>Answer</legend>
        using (Html.BeginForm("Anwser", "Puzzle"))
        {
            @Html.Hidden("puzzleId", Model.Id)
            @Html.TextArea("anwser", new { rows = 10, cols = 50 });
            <p>
                <input type="submit" value="Post Your Answer" />
            </p>
        }
    }


<p>
    @if (ViewBag.currentDeveloperId == Model.CreatedBy && Model.Status<(int)EnumPostStatus.Rewarding )
    {
        @Html.ActionLink("Edit", "Edit", new { id=Model.Id })  
    }
    
    @Html.ActionLink("Back to List", "Index")
</p>
